package com.woniuxy.controller;

import com.woniuxy.Exception.serviceException;
import com.woniuxy.entity.*;
import com.woniuxy.service.DrugAddService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@RestController
public class DrugAddController {

    @Resource
    DrugAddService drugAddService;

//    药品入库界面类型信息查询
    @PostMapping("/pe")
    public ResponseResult<List<DrugPeople>> selectKind(){

        List<DrugPeople> drugPeople=drugAddService.selectPeople();

        ResponseResult<List<DrugPeople>> responseResult=new ResponseResult<>(200,"ok",drugPeople);
        return responseResult;
    }

//    药品入库界面弹框信息查询
    @PostMapping("/de")
    public ResponseResult<List<DrugRepertory>> selectDrug( String name, Integer kind){


        List<DrugRepertory> drugRepertories=drugAddService.selectRepertory(name,kind);

        ResponseResult<List<DrugRepertory>> responseText = new ResponseResult<List<DrugRepertory>>(200, "success", drugRepertories);

        return responseText;
    }

//    药品入库
    @PostMapping("ae")
    public ResponseResult addDrug(@RequestBody DrugOrder drugOrder){
        System.out.println("进入方法");
        System.out.println(drugOrder);
        try {
            drugAddService.updateInsterDrug(drugOrder);
        } catch (serviceException e) {
            return new ResponseResult(500,e.getMessage(),null);
        }

        return new ResponseResult(200,"success",null);
    }
}
